finding the critical values of a function